# @tool
class_name HadDamageEffect
extends Sprite2D


@export var target: Character
@export var sprite: Sprite2D
@export var duration: float = 0.15



func _ready() -> void:
    target.handle_damage_signals.receive_damage_applied.connect(
        func(_info: DamageInfo) -> void:
            setup(sprite.texture, sprite.global_position, sprite.flip_h, sprite.flip_v,
                    Vector2i(sprite.hframes, sprite.vframes), sprite.frame, 
                    sprite.region_enabled, sprite.region_rect)
            sprite.hide()
            show()

            await get_tree().create_timer(duration).timeout
            sprite.show()
            hide()
    )

    hide()


func setup(texture_: Texture2D, pos: Vector2, flip_h_: bool, flip_v_: bool, 
            frames: Vector2i, frame_: int, region_enabled_: bool, region_rect_: Rect2) -> void:
    texture = texture_
    global_position = pos
    flip_h = flip_h_
    flip_v = flip_v_
    hframes = frames.x
    vframes = frames.y
    frame = frame_
    region_enabled = region_enabled_
    region_rect = region_rect_


# # 设置节点配置警告，脚本需是工具脚本
# func _get_configuration_warnings() -> PackedStringArray:
#     var warnings = PackedStringArray()

#     if get_scene_file_path() == "":
#         warnings.append("请从保存的场景实例化该节点，以确保正常工作")

#     return warnings
